package com.weizhi.logscripts;

import java.io.File;
import java.util.HashSet;
import java.util.Set;

public class ReadFileAndPath {
	
	public static String path_input="F:\\日志对账\\";
	public static String path_onput="E:\\日志对账\\";
	
	public static Set<String> set = new HashSet<String>();
	public static Set<String> confindeeset = new HashSet<String>();

	public static void main(String[] args) {
		String date = DateUtil.current("yyyy-MM-dd");
//		date = "2017-03-07";
		path_input +=date;
		path_onput +=date;
		String empifileName =path_onput+ "\\empi.txt";
		//创建输出目录
		createDir(path_onput,empifileName);
		getFile(path_input,empifileName);
		//读完所有文件后再处理全局变量
		ReadFromFile.verifyProcessState();
		ReadFromFile.confindeeset();
		System.out.println("错误处理完成！");
		System.out.println("empi拼装sql开始");
		EmpiFileToSQL.createSql(empifileName);
		System.out.println("empi拼装sql结束");
		System.out.println("全部完成！");
		
	}
	
	public static void createDir(String path_onput,String empifileName){
		
		String name = "F:\\verifyProcess.txt";
    	File verifyfile=new File(name);
		if(verifyfile.exists()){
			DeleteDirectory.deleteDir(verifyfile);
		}
		
		String name2 = "F:\\confindeeset.txt";
    	File verifyfile2=new File(name2);
		if(verifyfile2.exists()){
			DeleteDirectory.deleteDir(verifyfile2);
		}
		
		
		File empifile=new File(empifileName);
		if(empifile.exists()){
			DeleteDirectory.deleteDir(empifile);
		}
		
		File file=new File(path_onput);
		if(file.exists()){
			DeleteDirectory.deleteDir(file);
		}
		try {
			file.mkdirs();
			File ehr=new File(path_onput+"\\ehr");
			ehr.mkdirs();
			File mic=new File(path_onput+"\\mic");
			mic.mkdirs();
			File scm=new File(path_onput+"\\scm");
			scm.mkdirs();
			File task=new File(path_onput+"\\task");
			task.mkdirs();
			File message=new File(path_onput+"\\message");
			message.mkdirs();
			File sh=new File(path_onput+"\\mic\\sh");
			sh.mkdirs();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}; 
	
	public static void getFile(String path,String empifileName){
		File file=new File(path);
		File[] tempList = file.listFiles();
		for(File tempfile : tempList){
			if(tempfile.isFile()){
				System.out.println("文     件："+tempfile+" 开始处理！");
				String filepath = tempfile.getPath();
				ReadFromFile.readFileByLines(filepath,empifileName);
				System.out.println("文     件："+tempfile+" 处理结束！");
			}
			if(tempfile.isDirectory()){
				String directorypath = tempfile.getPath();
				getFile(directorypath,empifileName);
			}
		}
	}

}
